package com.example.myapplication.network;

import com.example.myapplication.api.ApiService;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitClient {
    private static final String BASE_URL = "http://10.0.2.2:8080/"; // 模拟器本地地址10.0.2.2
    private static Retrofit retrofit;
    private static ApiService apiService;

    // 私有构造函数防止外部实例化
    private RetrofitClient() {}

    // 需要创建实例也就是发起请求连接
    public static ApiService getApiService() {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            apiService = retrofit.create(ApiService.class);
        }
        return apiService;
    }
}